package com.fz.action;

import com.opensymphony.xwork2.ActionSupport;
import lombok.Data;
import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

import java.io.File;
import java.io.IOException;

/**
 * Created by Z-C-Y on 2018-02-27.
 * 使用Struts框架进行文件的上传
 */
@Data
public class Upload extends ActionSupport{
    private File file;
    private String fileContentType;//得到上传文件
    private String fileFileName;//得到上传文件的名称
    private String name;//得到表单提交的 名字

    public String execute() throws IOException {
        System.out.println(name);
        System.out.println(fileContentType);
        System.out.println(fileFileName);
        String path = ServletActionContext.getServletContext().getRealPath("/abc");
        File f = new File(path);
        if(!f.exists()){
            f.mkdirs();
        }
        FileUtils.copyFile(file,new File(path,fileFileName));
        return null;

    }



}
